// 七牛云AI API测试脚本
const crypto = require('crypto');

// 使用您提供的AccessKey作为API Key进行测试
const apiKey = 'hKTj5Z46h-BKXumnyr1Apl6KX3zB6F8E3MZcUhpQ';

// 测试API调用
async function testQnaigcAPI() {
    const url = 'https://api.qnaigc.com/v1/chat/completions';
    const body = JSON.stringify({
        model: 'deepseek-v3',
        messages: [
            {
                role: 'system',
                content: 'You are a helpful assistant.'
            },
            {
                role: 'user',
                content: 'Hello, please respond with "API Key is valid"'
            }
        ],
        max_tokens: 50
    });

    console.log('🧪 测试七牛云AI API...');
    console.log('URL:', url);
    console.log('API Key:', apiKey.substring(0, 10) + '...');

    try {
        const response = await fetch(url, {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${apiKey}`,
                'Content-Type': 'application/json'
            },
            body: body
        });

        const data = await response.json();

        if (response.ok) {
            console.log('✅ 七牛云AI API调用成功！');
            console.log('📝 响应:', data.choices[0].message.content);
        } else {
            console.log('❌ API调用失败:');
            console.log('   状态码:', response.status);
            console.log('   错误信息:', data);
        }
    } catch (error) {
        console.log('❌ 网络错误:', error.message);
    }
}

// 运行测试
testQnaigcAPI();
